SUBROUTINE TAG_A
* Demonstrate the RWA_TAG subroutine.* Include the RealWeb definitions
INCLUDE #RW.INCLUDE.DEFS FROM /SYSFILES/REALWEB,BP
EQU LF TO CHAR(10)
* Start the HTML page.CALL RW_START_HTML_PAGE("RWA_TAG Example", "", "", "", "")
HTML = ""
* Insert a paragraph containing some text.CALL RW_START_PARA("", "")
CALL RW_PUT("The following example shows how to check that a " : ...
"function is invoked with the correct number of " : ...
"parameters, since JavaScript doesn't do this for you:")
CALL RW_END_PARA* Insert the JavaScript example, with green comments.CALL RW_FIXED_ONCALL RW_PUT("function f(x, y, z) {" : LF)
* Define a JavaScript comment.
CODE = " "
CMT = "// First check that the right number of parameters were passed."
* Make it green, using the span tag and the style attribute.CALL RWA_TAG(CODE, "span", CMT, 'style="color: green"')CALL RW_PUT(CODE : " if (arguments.length != 3) {" : LF : ...
" alert('function f called with ' + arguments.length + " : LF : ...
" 'parameters - 3 parameters expected.');" : LF : ...
" return null;" : LF : ...
" }" : LF)
* Define another green JavaScript comment.
CODE = " "
CMT = "// Now do the actual function..."
CALL RWA_TAG(CODE, "span", CMT, 'style="color: green"')CALL RW_PUT(CODE : "}")CALL RW_FIXED_OFF* Complete the page.CALL RW_END_PAGE
RETURN
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><META NAME="Generator" CONTENT="Reality"><TITLE>RWA_TAG Example</TITLE></HEAD><BODY><P>
The following example shows how to check that a function is invoked with the correct number of parameters, since JavaScript doesn't do this for you:
</P><PRE>function f(x, y, z) {
<span style="color: green">// First check that the right number of parameters were passed.</span>
if (arguments.length != 3) {
alert('function f called with ' + arguments.length +
'parameters - 3 parameters expected.');
return null;
}
<span style="color: green">// Now do the actual function...</span>
}</PRE></BODY></HTML>